install.packages("ggplot2")
help(package = "ggplot2")
install.packages("readstata13")


library(foreign)
library(readstata13)
library(ggplot2)
pensions <- read.dta13("/Users/new/Dropbox/Dissertation/Data/pensions2017.dta")
pensions2 <- subset(pensions, fy <= 2011 & fy > 2000) 
detatch(pensions2)
attach(pensions2)
mean(pensions2$actfundratio, na.rm = TRUE)
mean(funding_riskless, na.rm = TRUE)

theme_set(theme_gray(base_size = 18))


# now i want to find the nummber of plans funded above 100 in each year
sum(fullarc >= 1) # this gives me the number of total observations above
mean(fullarc)
sum(fullarc >= 1 & fy == 2001) # this is the count of variables in 2001

yearmake <- array(dim=11)
yearmake[1] <- sum(fullarc >= 1 & fy == 2001)
yearmake[1]

for (i in 2001:2011) {
   yearmake[i] <- ((sum(fullarc >= 1 & fy ==i)) / 103) * 100
}

plot(yearmake)
plot(yearmake, xlab="Fiscal Year", yaxs="i", xaxs="r", ylab="% of Plans", type="l", xlim=range(2000:2012), ylim=range(20:100))
line(yearmake, xlim=range(2001:2011))

ggplot(yearmake)
qplot(yearmake)

hist(percentarc)
ggplot(percentarc, )
qplot(percentarc, xlab="Percent of ARC Made", bins = 45)
qplot(log_arc)
hist(log_arc, density = .1)

qplot(percentarc, actfundratio)
qplot(actfundratio, xlab="Actuarial Funding Ratio", bins=50)

qplot(fy, actfundratio, geom="line", na.rm=TRUE)


# this plots average funding over time - riskless


ggplot(pensions2) + 
  geom_smooth(aes(x=fy, y= risklessliabs/1000, colour="Liabilities"), na.rm=T) +
  geom_point(aes(x=fy,  y= risklessliabs/1000, colour="Liabilities"),size=.005,shape=5) + 
  geom_point(aes(x=fy,  y= actassets/1000, colour="Assets"),size=.005,shape=5) + 
  geom_smooth(aes(x=fy, y= actassets/1000, colour="Assets"),  na.rm=T) +
  theme(text= element_text(size=14)) +
  scale_colour_manual("", 
                      breaks = c("Liabilities", "Assets"),
                      values = c("red", "blue")) +
  scale_x_continuous(limits = c(2001, 2011), breaks = seq(2001,2011,2)) +
  scale_y_continuous(limits = c(0,35000), breaks = seq(0,35000,5000)) +
  xlab("Fiscal Year") +  ylab("Thousands of Dollars") 



## this is the one that gives you a legend just for the line - it works

ggplot(pensions2) + 
  geom_point(aes(x=fy,  y= funding_riskless, colour="Plan-Year Funded Obs."),size=.8,shape=6) + 
  geom_smooth(aes(x=fy, y=funding_riskless, colour="Smooth Funded Trend"), se=FALSE) +
  theme(text= element_text(size=14)) +
  scale_colour_manual("", 
                      breaks = c("Plan-Year Funded Obs.", "Smooth Funded Trend"),
                      values = c("gray53", "black")) +
  scale_x_continuous(limits = c(2001, 2011), breaks = seq(2001,2011,1)) +
  scale_y_continuous(limits = c(0,1), breaks = seq(0,1,.1)) +
  xlab("Fiscal Year") +  ylab("Funded Ratio (Assets/Liabs.)")
dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/funding_time.pdf")



#presentation
ggplot(pensions2,aes(x = fy,y = funding_riskless), na.rm=TRUE) +
  geom_point(colour = "dimgray",size=.65,shape=5) + 
  scale_y_continuous(limits = c(.1,1), breaks = seq(.1,1,.1)) +
  theme(text= element_text(size=28)) +
  geom_smooth(colour = "black",size = 1.5) +
  scale_x_continuous(limits = c(2001, 2011), breaks = seq(2001,2011,2)) +
  xlab("Fiscal Year") + ylab("Actuarial Funded Ratio") 
dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/funding_time_presentation.pdf")

mean(arcrate_percent, na.rm = TRUE)
mean(ercont100, na.rm = TRUE)


# now time to plot required vs. actual contribution rate
ggplot(pensions2) + 
  geom_smooth(aes(x=fy, y= arcrate_percent, colour="Required Cont. Trend"), se=FALSE, na.rm=T) +
  geom_smooth(aes(x=fy, y= ercont100/100, colour="Actual Cont. Trend"), se=FALSE, na.rm=T) +
  theme(text= element_text(size=12),
        axis.text.x = element_text(size=14),
        axis.text.y = element_text(size=14),
        axis.title.x = element_text(size=14),
        axis.title.y = element_text(size=14)) +
  scale_colour_manual("",  
        breaks = c("Required Cont. Trend", "Actual Cont. Trend"),
        values = c("black", "grey50")) +
  scale_x_continuous(limits = c(2001, 2011), breaks = seq(2001,2011,1)) +
  scale_y_continuous(limits = c(0,.16), breaks = seq(0,.16,0.02)) +
  xlab("Fiscal Year") +  ylab("Employer Contribution/Payroll") 
dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/Contributions.pdf")

# presentation version 
ggplot(pensions2) + 
  geom_smooth(aes(x=fy, y= arcrate_percent/100, colour="Required Contributions")) +
  geom_smooth(aes(x=fy, y= ercont100/100, colour="Actual Contributions")) +
  theme(text= element_text(size=14),
        axis.text.x = element_text(size=18),
        axis.text.y = element_text(size=18),
        axis.title.x = element_text(size=18),
        axis.title.y = element_text(size=18)) +
  scale_colour_manual("", 
                      breaks = c("Required Contributions", "Actual Contributions"),
                      values = c("red", "blue")) +
  scale_x_continuous(limits = c(2001, 2011), breaks = seq(2001,2011,2)) +
  scale_y_continuous(limits = c(0,.15), breaks = seq(0,.15,0.02)) +
  xlab("Fiscal Year") +  ylab("Contributions/Payroll") 
dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/actualVsRequired_presentation.pdf")

### here i'll plot the employee contribution rate
ggplot(pensions2) + 
  geom_point(aes(x=fy,  y= eecont_percent, colour="Plan-Year Cont. Obs."),size=.8,shape=6) + 
  geom_smooth(aes(x=fy, y=eecont_percent, colour="Employee Cont. Trend"), se=FALSE) +
  theme(text= element_text(size=14)) +
  scale_colour_manual("", 
                      breaks = c("Plan-Year Cont. Obs.", "Employee Cont. Trend"),
                      values = c("gray53", "black")) +
  scale_x_continuous(limits = c(2001, 2011), breaks = seq(2001,2011,1)) +
  scale_y_continuous(limits = c(0,.16), breaks = seq(0,.16,.02)) +
  xlab("Fiscal Year") +  ylab("Contributions/Payroll")
dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/employeeCont.pdf")




  # paper version

ggplot(pensions2,aes(x = fy,y = eecont_percent), na.rm=TRUE) +
  geom_point(colour = "dimgray",size=.65,shape=5) + 
  scale_y_continuous(limits = c(0,.14), breaks = seq(0,.14,.02)) +
  theme(text= element_text(size=14)) +
  geom_smooth(colour = "black",size = 1.5) +
  scale_x_continuous(limits = c(2001, 2011), breaks = seq(2001,2011,2)) +
  xlab("Fiscal Year") + ylab("Contributions/Payroll")
dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/employeeCont.pdf")


  # presentation version
ggplot(pensions2,aes(x = fy,y = eecont_percent), na.rm=TRUE) +
  geom_point(colour = "dimgray",size=.65,shape=5) + 
  scale_y_continuous(limits = c(0,.14), breaks = seq(0,.14,.02)) +
  theme(text= element_text(size=24)) +
  geom_smooth(colour = "black",size = 1.5) +
  scale_x_continuous(limits = c(2001, 2011), breaks = seq(2001,2011,2)) +
  xlab("Fiscal Year") + ylab("Contributions/Payroll")


#make a plot of mean retirements each year

mean(percent_retire2, na.rm=T)
ggplot(pensions,aes(x = fy,y = percent_retire2), na.rm=TRUE) +
  geom_point(colour = "dimgray",size=.65,shape=5) + 
  scale_y_continuous(limits = c(0,6), breaks = seq(0,6,.5)) +
  theme(text= element_text(size=24)) +
  geom_smooth(colour = "black",size = 1.5) +
  scale_x_continuous(limits = c(2001, 2011), breaks = seq(2001,2011,2)) +
  xlab("Fiscal Year") + ylab("Retirement Rate Proxy")
dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/employeeCont_presentation.pdf")

# histogram of retirement proxy
qplot(percent_retire2, xlab="Retirement Rate Proxy", bins = 50, na.rm=TRUE)

# now with the expected vs. actual return. try mean later
ggplot(pensions2) + 
  geom_smooth(aes(x=fy, y=invreturnassump*100, colour="Expected Returns Trend", linetype="Expected Returns Trend"), se=FALSE) +
  geom_smooth(aes(x=fy, y=investmentreturn_1yr*100, colour="Actual Returns Trend", linetype="Actual Returns Trend"),  se=FALSE) +
  geom_smooth(aes(x=fy, y=geom_mean_final*100, colour="Mean Actual Returns (2001-2011)", linetype="Mean Actual Returns (2001-2011)")) +
  theme(text= element_text(size=14)) +
  scale_linetype_manual("", 
                        breaks = c("Expected Returns Trend", "Actual Returns Trend", "Mean Actual Returns (2001-2011)"),
                        values = c("solid", "solid", "dashed")) +  
  scale_colour_manual("", 
                      breaks = c("Expected Returns Trend", "Actual Returns Trend", "Mean Actual Returns (2001-2011)"),
                      values = c("grey45", "black", "grey45")) +
  scale_x_continuous(limits = c(2001, 2011), breaks = seq(2001,2011,1)) +
  scale_y_continuous(limits = c(-12,15), breaks = seq(-12,15,3)) +
  xlab("Fiscal Year") +  ylab("Investment Returns (Percent)") +
  geom_hline(yintercept = 0, colour="gray58")
dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/actualVsExpected.pdf")


 mean(meaninv)
  #geom_hline(yintercept = mean(inv_return*100, na.rm=TRUE), na.rm=TRUE, show.legend=TRUE, linetype=3) +
 # geom_linerange(aes(x=fy, y=NULL, ymin=2001, ymax=2011), data=pensions2)
dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/actualVsExpected.pdf")

values = c("black", "grey50", "blue")) +
  

p + geom_hline(yintercept = mean(inv_return, na.rm=TRUE), na.rm=TRUE, show.legend=TRUE, )  
mean(inv_return)


### liabilities vs. assets over time

  ggplot(pensions2) + 
    geom_smooth(aes(x=fy, y= risklessliabs/1000, colour="Liabilities"), na.rm=T) +
    geom_point(aes(x=fy,  y= risklessliabs/1000, colour="Liabilities"),size=.005,shape=5) + 
    geom_point(aes(x=fy,  y= actassets/1000, colour="Assets"),size=.005,shape=5) + 
    geom_smooth(aes(x=fy, y= actassets/1000, colour="Assets"),  na.rm=T) +
    theme(text= element_text(size=14)) +
    scale_colour_manual("", 
                        breaks = c("Liabilities", "Assets"),
                        values = c("red", "blue")) +
    scale_x_continuous(limits = c(2001, 2011), breaks = seq(2001,2011,2)) +
    scale_y_continuous(limits = c(0,35000), breaks = seq(0,35000,5000)) +
    xlab("Fiscal Year") +  ylab("Thousands of Dollars") 
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/liabsVsAssets.pdf")
  
  mean(actassets, na.rm = T)
  
  #32 is presentation size
  
  
  ggplot(pensions2) + 
    geom_point(aes(x=political,  y= funding_riskless, colour="Plan Obs."),size=.8,shape=6) + 
    geom_smooth(aes(x=political, y=funding_riskless, colour="Correlation Trend"), se=FALSE) +
    theme(text= element_text(size=14)) +
    scale_colour_manual("", 
                        breaks = c("Plan Obs.", "Correlation Trend"),
                        values = c("gray53", "black")) +
    scale_x_continuous(limits = c(0, 1), breaks = seq(0,1,.1)) +
    scale_y_continuous(limits = c(0,1), breaks = seq(0,1,.2)) +
    xlab("Political/Total Trustees") +  ylab("Funded Ratio")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/politFunding_curved.pdf")

    ### politicization and funding
  
  # sraight version
  ggplot(pensions2,aes(x = political,y = funding_riskless), na.rm=TRUE) +
    geom_point(colour = "dimgray",size=.65,shape=5) + 
    scale_y_continuous(limits = c(.2,1), breaks = seq(.2,1,.20)) +
    theme(text= element_text(size=24)) +
    stat_smooth(colour = "black",size = 1.5,method="lm") +
    scale_x_continuous(limits = c(0, 1), breaks = seq(0,1,.2)) +
    xlab("Political/Total Trustees") + ylab("Funded Ratio")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/politFunding_straight.pdf")
  
  # curved version
  ggplot(pensions2,aes(x = political,y = funding_riskless), na.rm=TRUE) +
    geom_point(colour = "dimgray",size=.65,shape=5) + 
    scale_y_continuous(limits = c(0,1), breaks = seq(0,1,.2)) +
    theme(text= element_text(size=14)) +
     stat_smooth(colour = "black",size = 1.5) +
    scale_x_continuous(limits = c(0, 1), breaks = seq(0,1,.2)) +
    xlab("Political/Total Trustees") + ylab("Funded Ratio")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/politFunding_curved.pdf")
  
  # curved version - paper
  ggplot(pensions2,aes(x = political,y = funding_riskless), na.rm=TRUE) +
    geom_point(colour = "dimgray",size=.65,shape=5) + 
    scale_y_continuous(limits = c(0,1), breaks = seq(0,1,.2)) +
    theme(text= element_text(size=14)) +
    stat_smooth(colour = "black",size = 1.5) +
    scale_x_continuous(limits = c(0, 1), breaks = seq(0,1,.2)) +
    xlab("Political/Total Trustees") + ylab("Funded Ratio")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/politFunding_curved_paper.pdf")
  
  
  # actives and funding 
  
  # straight
   ggplot(pensions2,aes(x = active, y = funding_riskless), na.rm=TRUE) +
     geom_point(colour = "dimgray",size=.65,shape=5) + 
     scale_y_continuous(limits = c(.2,1), breaks = seq(.2,1,.20)) +
     theme(text= element_text(size=18)) +
     stat_smooth(colour = "black",size = 1.5,method="lm") +
     scale_x_continuous(limits = c(0, 1), breaks = seq(0,1,.2)) +
     xlab("Active/Total Trustees") + ylab("Funded Ratio")
   dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/activeFunding_straight.pdf")
   
   # curved
   ggplot(pensions2) + 
     geom_point(aes(x=active,  y= funding_riskless, colour="Plan Obs."),size=.8,shape=6) + 
     geom_smooth(aes(x=active, y=funding_riskless, colour="Correlation Trend"), se=FALSE) +
     theme(text= element_text(size=14)) +
     scale_colour_manual("", 
                         breaks = c("Plan Obs.", "Correlation Trend"),
                         values = c("gray53", "black")) +
     scale_x_continuous(limits = c(0, 1), breaks = seq(0,1,.1)) +
     scale_y_continuous(limits = c(0,1), breaks = seq(0,1,.2)) +
     xlab("Active/Total Trustees") +  ylab("Funded Ratio")
   dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/activeFunding_curved.pdf")
   
   ggplot(pensions2,aes(x = active, y = funding_riskless), na.rm=TRUE) +
     geom_point(colour = "dimgray",size=.65,shape=5) + 
     scale_y_continuous(limits = c(.2, 1), breaks = seq(.2,1,.2)) +
     theme(text= element_text(size=18)) +
     stat_smooth(colour = "black",size = 1.5) +
     scale_x_continuous(limits = c(0, 1), breaks = seq(0,1,.2)) +
     xlab("Active/Total Trustees") + ylab("Funded Ratio")
   dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/activeFunding_curved_paper.pdf")
   
   
   # retired and funding 
   
   # straight
   ggplot(pensions2,aes(x = retired, y = funding_riskless), na.rm=TRUE) +
     geom_point(colour = "dimgray",size=.65,shape=5) + 
     scale_y_continuous(limits = c(.2,1), breaks = seq(.2,1,.20)) +
     theme(text= element_text(size=18)) +
     stat_smooth(colour = "black",size = 1.5,method="lm") +
     scale_x_continuous(limits = c(0, 1), breaks = seq(0,1,.1)) +
     xlab("Retired/Total Trustees") + ylab("Funded Ratio")
   dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/retiredFunding_straight.pdf")
   
   # curved
   ggplot(pensions2) + 
     geom_point(aes(x=retired,  y= funding_riskless, colour="Plan Obs."),size=.8,shape=6) + 
     geom_smooth(aes(x=retired, y=funding_riskless, colour="Correlation Trend"), se=FALSE) +
     theme(text= element_text(size=14)) +
     scale_colour_manual("", 
                         breaks = c("Plan Obs.", "Correlation Trend"),
                         values = c("gray53", "black")) +
     scale_x_continuous(limits = c(0, 1), breaks = seq(0,1,.1)) +
     scale_y_continuous(limits = c(0,1), breaks = seq(0,1,.2)) +
     xlab("Retired/Total Trustees") +  ylab("Funded Ratio")
   dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/retiredFunding_curved.pdf")
   
   # participants and funding 
   
   # straight
   ggplot(pensions2,aes(x = participants, y = funding_riskless), na.rm=TRUE) +
     geom_point(colour = "dimgray",size=.65,shape=5) + 
     scale_y_continuous(limits = c(.2,1), breaks = seq(.2,1,.20)) +
     theme(text= element_text(size=24)) +
     stat_smooth(colour = "black",size = 1.5,method="lm") +
     scale_x_continuous(limits = c(0, 1), breaks = seq(0,1,.2)) +
     xlab("% Participants on Board") + ylab("Funded Ratio")
   dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/participantsFunding_straight.pdf")
   
   # curved
   ggplot(pensions2,aes(x = participants, y = funding_riskless), na.rm=TRUE) +
     geom_point(colour = "dimgray",size=.65,shape=5) + 
     scale_y_continuous(limits = c(0,1.2), breaks = seq(0,1.2,.2)) +
     theme(text= element_text(size=14)) +
     stat_smooth(colour = "black",size = 1.5) +
     scale_x_continuous(limits = c(0, 1), breaks = seq(0,1,.2)) +
     xlab("% Participants on Board") + ylab("Funded Ratio")
   dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/participantsFunding_curved.pdf")
   
   

  # hist of the assets
  ggplot(pensions2,aes(actassets/10000), na.rm=TRUE) +
    geom_histogram(bins=70) +
    theme(text= element_text(size=14)) +
    scale_x_continuous(limits = c(0,4000), breaks = seq(0,4000,1000)) +
    xlab("Assets ($100 Thousands)") + ylab("Plan Count")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/assetsHist.pdf")
  
  
  # hist of the liabilities
  ggplot(pensions2,aes(actliabs/1000), na.rm=TRUE) +
    geom_histogram(bins=70) +
    theme(text= element_text(size=24)) +
    scale_x_continuous(limits = c(0,200000), breaks = seq(0,200000,50000)) +
    xlab("Liabilities (Thousands of Dollars)") + ylab("Plan Count")
  
  # hist of the riskless liabilies 
  ggplot(pensions2,aes(risklessliabs/100000), na.rm=TRUE) +
    geom_histogram(bins=70) +
    theme(text= element_text(size=14)) +
    scale_x_continuous(limits = c(0,4000), breaks = seq(0,4000,1000)) +
    xlab("Riskless Liabilities ($100 Thousands)") + ylab("Plan Count")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/risklessLiabsHist.pdf")
  
  # hist of political
  ggplot(pensions2,aes(political), na.rm=TRUE) +
    geom_histogram(bins=30) +
    theme(text= element_text(size=24)) +
    scale_x_continuous(limits = c(-0.05,1.05), breaks = seq(0,1,.2)) +
   # scale_y_continuous(limits = c(0,100), breaks = seq(0,100,25)) +
    xlab("Board Politicization") + ylab("Plan-Year Count")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/politicalHist.pdf")
  
 
  # hist of active 
  ggplot(pensions2,aes(active), na.rm=TRUE) +
    geom_histogram(bins=30) +
    theme(text= element_text(size=24)) +
    scale_x_continuous(limits = c(-0.05,1.05), breaks = seq(0,1,.2)) +
    xlab("Board % Active") +  ylab("Plan-Year Count")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/activeHist.pdf")
  
  
  # hist of retired
  ggplot(pensions2,aes(retired), na.rm=TRUE) +
    geom_histogram(bins=30) +
    theme(text= element_text(size=24)) +
    scale_x_continuous(limits = c(-0.05,1.05), breaks = seq(0,1,.2)) +
    xlab("Board % Retired") +  ylab("Plan-Year Count")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/retiredHist.pdf")
  
  
  # hist of participants
  ggplot(pensions2,aes(participants), na.rm=TRUE) +
    geom_histogram(bins=30) +
    theme(text= element_text(size=24)) +
    scale_x_continuous(limits = c(-0.05,1.05), breaks = seq(0,1,.2)) +
    xlab("Board % Participants") +  ylab("Plan-Year Count")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/participantsHist.pdf")
  
  
  # board politicization over time
  ggplot(pensions2,aes(x = fy,y = political), na.rm=TRUE) +
    geom_point(colour = "dimgray",size=.65,shape=5) + 
    scale_y_continuous(limits = c(0,1), breaks = seq(0,1,.1)) +
    geom_smooth(colour = "black",size = 1.5) +
    theme(text= element_text(size=14)) +
    scale_x_continuous(limits = c(2001, 2011), breaks = seq(2001,2011,2)) +
    xlab("Fiscal Year") + ylab("Board Politicization")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/politicalTime.pdf")
  
  # board actives over time
  ggplot(pensions2,aes(x = fy,y = active), na.rm=TRUE) +
    geom_point(colour = "dimgray",size=.65,shape=5) + 
    scale_y_continuous(limits = c(0,1), breaks = seq(0,1,.1)) +
    geom_smooth(colour = "black",size = 1.5) +
    theme(text= element_text(size=14)) +
    scale_x_continuous(limits = c(2001, 2011), breaks = seq(2001,2011,2)) +
    xlab("Fiscal Year") + ylab("Board Politicization")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/activeTime.pdf")
  
  # board retired over time

  ggplot(pensions2,aes(x = fy,y = retired), na.rm=TRUE) +
    geom_point(colour = "dimgray",size=.65,shape=5) + 
    scale_y_continuous(limits = c(0,1), breaks = seq(0,1,.1)) +
    geom_smooth(colour = "black",size = 1.5) +
    theme(text= element_text(size=14)) +
    scale_x_continuous(limits = c(2001, 2011), breaks = seq(2001,2011,2)) +
    xlab("Fiscal Year") + ylab("Board % Retired")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/retiredTime.pdf")
  
  # board participants over time
  ggplot(pensions2,aes(x = fy,y = participants), na.rm=TRUE) +
    geom_point(colour = "dimgray",size=.65,shape=5) + 
    scale_y_continuous(limits = c(0,1), breaks = seq(0,1,.1)) +
    geom_smooth(colour = "black",size = 1.5) +
    theme(text= element_text(size=14)) +
    scale_x_continuous(limits = c(2001, 2011), breaks = seq(2001,2011,2)) +
    xlab("Fiscal Year") + ylab("Board % Participants")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/participantsTime.pdf")
  
  
  # equities over time
  ggplot(pensions2) + 
    geom_point(aes(x=fy,  y= equities, colour="Plan-Year Equities Obs."),size=.8,shape=6) + 
    geom_smooth(aes(x=fy, y=equities, colour="Equities Trend"), se=FALSE) +
    theme(text= element_text(size=14)) +
    scale_colour_manual("", 
                        breaks = c("Plan-Year Equities Obs.", "Equities Trend"),
                        values = c("gray53", "black")) +
    scale_x_continuous(limits = c(2001, 2011), breaks = seq(2001,2011,1)) +
    scale_y_continuous(limits = c(0,1), breaks = seq(0,1,.1)) +
    xlab("Fiscal Year") +  ylab("Investments in Equities")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/equitiesTime.pdf")
  
  # alternatives over time
  ggplot(pensions2) + 
    geom_point(aes(x=fy,  y= alternatives, colour="Plan-Year Alternatives Obs."),size=.8,shape=6) + 
    geom_smooth(aes(x=fy, y=alternatives, colour="Alternatives Trend"), se=FALSE) +
    theme(text= element_text(size=14)) +
    scale_colour_manual("", 
                        breaks = c("Plan-Year Alternatives Obs.", "Alternatives Trend"),
                        values = c("gray53", "black")) +
    scale_x_continuous(limits = c(2001, 2011), breaks = seq(2001,2011,1)) +
    scale_y_continuous(limits = c(0,.6), breaks = seq(0,.6,.05)) +
    xlab("Fiscal Year") +  ylab("Investments in Alternatives")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/alternativesTime.pdf")
  
  # real estate over time
  ggplot(pensions2) + 
    geom_point(aes(x=fy,  y= realestate, colour="Plan-Year Real Estate Obs."),size=.8,shape=6) + 
    geom_smooth(aes(x=fy, y=realestate, colour="Real Estate Trend"), se=FALSE) +
    theme(text= element_text(size=14)) +
    scale_colour_manual("", 
                        breaks = c("Plan-Year Real Estate Obs.", "Real Estate Trend"),
                        values = c("gray53", "black")) +
    scale_x_continuous(limits = c(2001, 2011), breaks = seq(2001,2011,1)) +
    scale_y_continuous(limits = c(0,.2), breaks = seq(0,.2,.05)) +
    xlab("Fiscal Year") +  ylab("Investments in Real Estate")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/realestateTime.pdf")
  
  # bonds over time
  ggplot(pensions2) + 
    geom_point(aes(x=fy,  y= bonds, colour="Plan-Year Bonds Obs."),size=.8,shape=6) + 
    geom_smooth(aes(x=fy, y=bonds, colour="Bonds Trend"), se=FALSE) +
    theme(text= element_text(size=14)) +
    scale_colour_manual("", 
                        breaks = c("Plan-Year Bonds Obs.", "Bonds Trend"),
                        values = c("gray53", "black")) +
    scale_x_continuous(limits = c(2001, 2011), breaks = seq(2001,2011,1)) +
    scale_y_continuous(limits = c(0,1), breaks = seq(0,1,.1)) +
    xlab("Fiscal Year") +  ylab("Investments in Bonds")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/bondsTime.pdf")
  

  
  ggplot(pensions2,aes(x = fy,y = realestate), na.rm=TRUE) +
    geom_point(colour = "dimgray",size=.65,shape=5) + 
    theme(text= element_text(size=14)) +
     scale_y_continuous(limits = c(0,.2), breaks = seq(0,.2,.05)) +
    geom_smooth(colour = "black",size = 1.5) +
    scale_x_continuous(limits = c(2001, 2011), breaks = seq(2001,2011,2)) +
    xlab("Fiscal Year") + ylab("Investment in Real Estate")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/realestateTime.pdf")
  
  
  ggplot(pensions2,aes(x = fy,y = bonds), na.rm=TRUE) +
    geom_point(colour = "dimgray",size=.65,shape=5) + 
    theme(text= element_text(size=14)) +
    scale_y_continuous(limits = c(.1,.40), breaks = seq(.1,.40,.05)) +
    geom_smooth(colour = "black",size = 1.5) +
    scale_x_continuous(limits = c(2001, 2011), breaks = seq(2001,2011,2)) +
    xlab("Fiscal Year") + ylab("Investment in Bonds")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/bondsTime.pdf")
  
  
  ### Percent Republican and Funding
  
  ggplot(pensions2,aes(x = repub_shareper,y = funding_riskless), na.rm=TRUE) +
    geom_point(colour = "dimgray",size=.65,shape=5) + 
    scale_y_continuous(limits = c(0,1), breaks = seq(0,1,.2)) +
    theme(text= element_text(size=14)) +
    geom_smooth(colour = "black",size = 1.5) +
    scale_x_continuous(limits = c(0, .9), breaks = seq(0,.9,.1)) +
    xlab("Percent Republican") + ylab("Funded Ratio")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/repubFunding.pdf")
  
  
  # union coverage and funding
  ggplot(pensions2,aes(x = perunioncov/100,y = funding_riskless), na.rm=TRUE) +
    geom_point(colour = "dimgray",size=.65,shape=5) + 
    theme(text= element_text(size=14)) +
    scale_y_continuous(limits = c(0,1), breaks = seq(0,1,.2)) +
    geom_smooth(colour = "black",size = 1.5) +
    scale_x_continuous(limits = c(.09, .8), breaks = seq(.1,.8,.1)) +
    xlab("Union Coverage") + ylab("Funded Ratio")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/unionFunding.pdf")
  
  
  #liabrev histogram
  ggplot(pensions2,aes(liabrev_r), na.rm=TRUE) +
    geom_histogram(bins=40) +
    theme(text= element_text(size=14)) +
    scale_x_continuous(limits = c(-.1,5.1), breaks = seq(0,5,1)) +
    xlab("Ratio of Plan-Year Riskless Liabilities to State Revenue") + ylab("Plan-Year Count")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/liabrev_hist.pdf")
  
  
  ggplot(pensions2,aes(liabrev_r), na.rm=TRUE) +
    geom_histogram(bins=40) +
    theme(text= element_text(size=14)) +
    scale_x_continuous(limits = c(-.1,5.1), breaks = seq(0,5,1)) +
    xlab("Plan-Year Riskless Liabilities/State Revenue") + ylab("Plan-Year Count")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/liabrev_hist_pres.pdf")
  
  
  # funding histogram
  ggplot(pensions2,aes(funding_riskless), na.rm=TRUE) +
    geom_histogram(bins=45) +
    theme(text= element_text(size=14)) +
    scale_x_continuous(limits = c(0,1.25), breaks = seq(0,1.25,.25)) +
    xlab("Actuarial Funded Ratio") + ylab("Plan-Year Count")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/funded_hist.pdf")
  
  
  ggplot(pensions2,aes(actfundratio), na.rm=TRUE) +
    geom_histogram(bins=45) +
    theme(text= element_text(size=14)) +
    scale_x_continuous(limits = c(0,1.25), breaks = seq(0,1.25,.25)) +
    xlab("Actuarial Funded Ratio") + ylab("Plan-Year Count")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/funded_hist_self.pdf")
  
  
  
  # riskless funding histogram
  ggplot(pensions2,aes(funding_riskless), na.rm=TRUE) +
    geom_histogram(bins=45) +
    theme(text= element_text(size=16)) +
    scale_x_continuous(limits = c(0,1.25), breaks = seq(0,1.25,.25)) +
    xlab("Actuarial Funded Ratio") + ylab("Plan Count")
  
  ggplot(pensions2,aes(funding_riskless), na.rm=TRUE) +
    geom_histogram(bins=45) +
    theme(text= element_text(size=32)) +
    scale_x_continuous(limits = c(0,2.0), breaks = seq(0,2,.5)) +
    xlab("Actuarial Funding Ratio") + ylab("Plan Count")
  
  
  ### discount rate and boards bivars
  
  ggplot(pensions2) + 
    geom_point(aes(x=political,  y=invreturnassump2 , colour="Plan Obs."),size=.8,shape=6) + 
    geom_smooth(aes(x=political, y=invreturnassump2, colour="Correlation Trend"), se=FALSE) +
    theme(text= element_text(size=14)) +
    scale_colour_manual("", 
                        breaks = c("Plan Obs.", "Correlation Trend"),
                        values = c("gray53", "black")) +
    scale_x_continuous(limits = c(0, 1), breaks = seq(0,1,.1)) +
    scale_y_continuous(limits = c(5,11), breaks = seq(5,11,1)) +
    xlab("Political/Total Trustees") +  ylab("Discount Rate")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/politicalDiscount_curved.pdf")
  
  ggplot(pensions2) + 
    geom_point(aes(x=active,  y=invreturnassump2, colour="Plan Obs."),size=.8,shape=6) + 
    geom_smooth(aes(x=active, y=invreturnassump2, colour="Correlation Trend"), se=FALSE) +
    theme(text= element_text(size=14)) +
    scale_colour_manual("", 
                        breaks = c("Plan Obs.", "Correlation Trend"),
                        values = c("gray53", "black")) +
    scale_x_continuous(limits = c(0, 1), breaks = seq(0,1,.1)) +
    scale_y_continuous(limits = c(5,11), breaks = seq(5,11,1)) +
    xlab("Active/Total Trustees") +  ylab("Discount Rate")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/activeDiscount_curved.pdf")
  
  ggplot(pensions2) + 
    geom_point(aes(x=retired,  y=invreturnassump2, colour="Plan Obs."),size=.8,shape=6) + 
    geom_smooth(aes(x=retired, y=invreturnassump2, colour="Correlation Trend"), se=FALSE) +
    theme(text= element_text(size=14)) +
    scale_colour_manual("", 
                        breaks = c("Plan Obs.", "Correlation Trend"),
                        values = c("gray53", "black")) +
    scale_x_continuous(limits = c(0, 1), breaks = seq(0,1,.1)) +
    scale_y_continuous(limits = c(5,11), breaks = seq(5,11,1)) +
    xlab("Retired/Total Trustees") +  ylab("Discount Rate")
  dev.print(pdf, "/Users/JohnBrooks/Dropbox/Dissertation/Images/retiredDiscount_curved.pdf")
  
  
  

